<?php
/**
 * Created by JetBrains PhpStorm.
 * User: shaoshuai
 * Date: 11-10-2
 * Time: PM10:38
 */
include_once '../common.func.php';
if (!isset($posts)) {
    $posts = getPosts();
    $posts = array_values($posts);
}
if (!isset($page)) {
    $page = 1;
}

//html title
if (isset($title)) {
    $title = $title . ' - ';
} else {
    $title = '';
}

$postCount = count($posts);
$navs = getNavs();
$links = getLinks();
$categorys = getCategorys();
$tags = getTags();
$settings = getSettings();
?><!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title><?php echo $title, SITE_TITLE ?></title>
    <script src="<?php echo SITE_URL ?>/themes/default/js/html5.js"></script>
    <link href="<?php echo SITE_URL ?>/themes/default/css/normalize.css" rel="stylesheet" />
    <link href="<?php echo SITE_URL ?>/themes/default/css/article.css" rel="stylesheet" />
    <link href="<?php echo SITE_URL ?>/themes/default/css/index.css" rel="stylesheet" />
</head>
<body>
<header>
    <h1><span><?php echo $settings['title'] ?></span></h1>

    <p><?php echo $settings['describe'] ?></p>
    <nav>
        <ul>
            <?php
            foreach ($navs as $nav) {
            ?>
            <li><a href="<?php echo $nav['href'] ?>" target="<?php echo $nav['target'] ?>"><?php echo $nav['text'] ?>&nbsp;</a></li>
            <?php
            }
            ?>
        </ul>
    </nav>
</header>
<div id="content-wrapper">
    <aside>
        <nav>
            <h1>分类</h1>
            <ul>
                <?php foreach ($categorys as $id => $category) { ?>
                <li><a href="<?php echo $settings['base'] . '/category/' . $category['name'] . '.html' ?>" title="查看 <?php echo $category['name'] ?> 的全部文章"><?php echo $category['name'] ?></a></li>
                <?php } ?>
            </ul>
        </nav>
        <nav class="tag-nav">
            <h1>标签</h1>
            <ul>
                <?php foreach ($tags as $li) { ?>
                <li><a href="<?php echo $settings['base'] . '/tag/' . $li['name'] . '.html' ?>"><?php echo $li['name'] ?></a></li>
                <?php } ?>
            </ul>
        </nav>
        <nav>
            <h1>链接</h1>
            <ul>
                <?php foreach ($links as $li) { ?>
                <li><a href="<?php echo $li['href']/*article.php*/ ?>" target="_blank" title="<?php echo $li['title'] ?>"><?php echo $li['content']/*google*/ ?></a></li>
                <?php } ?>
            </ul>
        </nav>
    </aside>
    <section>
        <?php
        for ($i = 0; $i < $settings['page_size'] && $i < $postCount; $i++) {
            $post = $posts[$i];
        ?>
        <article class="post blog-content">
            <header class="post-header">
                <h2><a href="<?php echo $settings['base'] ?>/post/<?php echo $post['url'] ?>.html" title="<?php echo $post['title'] ?>"><?php echo $post['title'] ?></a></h2>

                <p>
                <?php echo date('Y-m-d H:i:s', intval($post['time'])); ?> | 
                <?php echo AUTHOR ?> | 
                <a href="<?php echo $settings['base'] ?>/post/<?php echo $post['url'] ?>.html#comments" title="查看评论"><?php echo count($post['comments']) ?> Comments</a> | 
                <?php 
                $categoryName = getCategoryNameById($post['category']);
                echo sprintf('<a href="%s/category/%s.html" title="查看 %s 的全部文章">%s</a>', $settings['base'], $categoryName, $categoryName, $categoryName);

                if (count($post['tag']) == 0) { 
                } else {
                    echo ' | ';
                    foreach ($post['tag'] as $postTag) {
                        echo sprintf('<a href="%s/tag/%s.html" title="所属标签 %s">%s</a>&nbsp;', $settings['base'], $postTag, $postTag, $postTag);
                    }
                }
                ?></p>
            </header>
            <div>
                <?php echo $post['content'] ?>
            </div>
        </article>
        <?php } ?>
    </section>
    <nav>
        <ul>
            <?php if ($prevPage) { ?>
            <li class="prev-page"><a href="<?php echo $settings['base'] . $documentRoot . '/' . $prevPage . '.html' ?>">上一页</a></li>
            <?php } ?>
            <?php if ($nextPage) { ?>
            <li class="next-page"><a href="<?php echo $settings['base'] . $documentRoot . '/' . $nextPage . '.html' ?>">下一页</a></li>
            <?php } ?>
        </ul>
    </nav>
</div>
<footer>
    <p><a href="http://paperblog.showframework.com/">Powered by Paper Blog</a></p>
</footer>
</body>
</html>
